/*
 * Copyright (C) from 2022 The Play Framework Contributors <https://github.com/playframework>, 2011-2021 Lightbend Inc. <https://www.lightbend.com>
 */

var assert = require("assert");
var jsRoutes = require("./jsRoutes");

describe("The JavaScript router for Float", function () {
    const defaultList = [1.1, 2.2, 3.3]
    const testList = [7.7, -8.8, 9.9e-10]
    const infinityList = [NaN, Infinity, -Infinity]
    it("should be correct for path param", function () {
        let path = "/float-p";
        var data = jsRoutes.controllers.FloatController.path(null);
        assert.equal(path + "/null", data.url);
        data = jsRoutes.controllers.FloatController.path();
        assert.equal(path + "/undefined", data.url);
        data = jsRoutes.controllers.FloatController.path(undefined);
        assert.equal(path + "/undefined", data.url);
        data = jsRoutes.controllers.FloatController.path(7.89);
        assert.equal(path + "/7.89", data.url);
        data = jsRoutes.controllers.FloatController.path(-7.89);
        assert.equal(path + "/-7.89", data.url);
        data = jsRoutes.controllers.FloatController.path(7.8e29);
        assert.equal(path + "/7.8e%2B29", data.url);
        data = jsRoutes.controllers.FloatController.path(7.8e-29);
        assert.equal(path + "/7.8e-29", data.url);
        data = jsRoutes.controllers.FloatController.path(NaN);
        assert.equal(path + "/NaN", data.url);
        data = jsRoutes.controllers.FloatController.path(Infinity);
        assert.equal(path + "/Infinity", data.url);
        data = jsRoutes.controllers.FloatController.path(-Infinity);
        assert.equal(path + "/-Infinity", data.url);
    });
    it("should be correct for query param", function () {
        let path = "/float";
        var data = jsRoutes.controllers.FloatController.query(null);
        assert.equal(path + "?x=null", data.url);
        data = jsRoutes.controllers.FloatController.query();
        assert.equal(path + "?x=undefined", data.url);
        data = jsRoutes.controllers.FloatController.query(undefined);
        assert.equal(path + "?x=undefined", data.url);
        data = jsRoutes.controllers.FloatController.query(7.89);
        assert.equal(path + "?x=7.89", data.url);
        data = jsRoutes.controllers.FloatController.query(-7.89);
        assert.equal(path + "?x=-7.89", data.url);
        data = jsRoutes.controllers.FloatController.query(7.8e29);
        assert.equal(path + "?x=7.8e%2B29", data.url);
        data = jsRoutes.controllers.FloatController.query(7.8e-29);
        assert.equal(path + "?x=7.8e-29", data.url);
        data = jsRoutes.controllers.FloatController.query(NaN);
        assert.equal(path + "?x=NaN", data.url);
        data = jsRoutes.controllers.FloatController.query(Infinity);
        assert.equal(path + "?x=Infinity", data.url);
        data = jsRoutes.controllers.FloatController.query(-Infinity);
        assert.equal(path + "?x=-Infinity", data.url);
    });
    it("should be correct for default query param", function () {
        let path = "/float-d";
        var data = jsRoutes.controllers.FloatController.queryDefault(null);
        assert.equal(path, data.url);
        data = jsRoutes.controllers.FloatController.queryDefault();
        assert.equal(path, data.url);
        data = jsRoutes.controllers.FloatController.queryDefault(undefined);
        assert.equal(path, data.url);
        data = jsRoutes.controllers.FloatController.queryDefault(7.89);
        assert.equal(path + "?x%3F%3D=7.89", data.url);
        data = jsRoutes.controllers.FloatController.queryDefault(-7.89);
        assert.equal(path + "?x%3F%3D=-7.89", data.url);
        data = jsRoutes.controllers.FloatController.queryDefault(7.8e29);
        assert.equal(path + "?x%3F%3D=7.8e%2B29", data.url);
        data = jsRoutes.controllers.FloatController.queryDefault(7.8e-29);
        assert.equal(path + "?x%3F%3D=7.8e-29", data.url);
        data = jsRoutes.controllers.FloatController.queryDefault(NaN);
        assert.equal(path + "?x%3F%3D=NaN", data.url);
        data = jsRoutes.controllers.FloatController.queryDefault(Infinity);
        assert.equal(path + "?x%3F%3D=Infinity", data.url);
        data = jsRoutes.controllers.FloatController.queryDefault(-Infinity);
        assert.equal(path + "?x%3F%3D=-Infinity", data.url);
    });
    it("should be correct for fixed query param", function () {
        let path = "/float-f";
        var data = jsRoutes.controllers.FloatController.queryFixed(null);
        assert.equal(path, data.url);
        data = jsRoutes.controllers.FloatController.queryFixed();
        assert.equal(path, data.url);
        data = jsRoutes.controllers.FloatController.queryFixed(undefined);
        assert.equal(path, data.url);
        data = jsRoutes.controllers.FloatController.queryFixed(7.89);
        assert.equal(path, data.url);
    });
    it("should be correct for nullable query param", function () {
        let path = "/float-null";
        var data = jsRoutes.controllers.FloatController.queryNullable(null);
        assert.equal(path, data.url);
        data = jsRoutes.controllers.FloatController.queryNullable();
        assert.equal(path, data.url);
        data = jsRoutes.controllers.FloatController.queryNullable(undefined);
        assert.equal(path, data.url);
        data = jsRoutes.controllers.FloatController.queryNullable(7.89);
        assert.equal(path + "?x%3F=7.89", data.url);
        data = jsRoutes.controllers.FloatController.queryNullable(-7.89);
        assert.equal(path + "?x%3F=-7.89", data.url);
        data = jsRoutes.controllers.FloatController.queryNullable(7.8e29);
        assert.equal(path + "?x%3F=7.8e%2B29", data.url);
        data = jsRoutes.controllers.FloatController.queryNullable(7.8e-29);
        assert.equal(path + "?x%3F=7.8e-29", data.url);
        data = jsRoutes.controllers.FloatController.queryNullable(NaN);
        assert.equal(path + "?x%3F=NaN", data.url);
        data = jsRoutes.controllers.FloatController.queryNullable(Infinity);
        assert.equal(path + "?x%3F=Infinity", data.url);
        data = jsRoutes.controllers.FloatController.queryNullable(-Infinity);
        assert.equal(path + "?x%3F=-Infinity", data.url);
    });
    it("should be correct for optional query param", function () {
        let path = "/float-opt";
        var data = jsRoutes.controllers.FloatController.queryOptional(null);
        assert.equal(path, data.url);
        data = jsRoutes.controllers.FloatController.queryOptional();
        assert.equal(path, data.url);
        data = jsRoutes.controllers.FloatController.queryOptional(undefined);
        assert.equal(path, data.url);
        data = jsRoutes.controllers.FloatController.queryOptional(7.89);
        assert.equal(path + "?x%3F=7.89", data.url);
        data = jsRoutes.controllers.FloatController.queryOptional(-7.89);
        assert.equal(path + "?x%3F=-7.89", data.url);
        data = jsRoutes.controllers.FloatController.queryOptional(7.8e29);
        assert.equal(path + "?x%3F=7.8e%2B29", data.url);
        data = jsRoutes.controllers.FloatController.queryOptional(7.8e-29);
        assert.equal(path + "?x%3F=7.8e-29", data.url);
        data = jsRoutes.controllers.FloatController.queryOptional(NaN);
        assert.equal(path + "?x%3F=NaN", data.url);
        data = jsRoutes.controllers.FloatController.queryOptional(Infinity);
        assert.equal(path + "?x%3F=Infinity", data.url);
        data = jsRoutes.controllers.FloatController.queryOptional(-Infinity);
        assert.equal(path + "?x%3F=-Infinity", data.url);
    });
    it("should be correct for optional default query param", function () {
        let path = "/float-opt-d";
        var data = jsRoutes.controllers.FloatController.queryOptionalDefault(null);
        assert.equal(path, data.url);
        data = jsRoutes.controllers.FloatController.queryOptionalDefault();
        assert.equal(path, data.url);
        data = jsRoutes.controllers.FloatController.queryOptionalDefault(undefined);
        assert.equal(path, data.url);
        data = jsRoutes.controllers.FloatController.queryOptionalDefault(1.23);
        assert.equal(path + "?x%3F%3D=1.23", data.url);
        data = jsRoutes.controllers.FloatController.queryOptionalDefault(7.89);
        assert.equal(path + "?x%3F%3D=7.89", data.url);
        data = jsRoutes.controllers.FloatController.queryOptionalDefault(7.8e29);
        assert.equal(path + "?x%3F%3D=7.8e%2B29", data.url);
        data = jsRoutes.controllers.FloatController.queryOptionalDefault(7.8e-29);
        assert.equal(path + "?x%3F%3D=7.8e-29", data.url);
        data = jsRoutes.controllers.FloatController.queryOptionalDefault(NaN);
        assert.equal(path + "?x%3F%3D=NaN", data.url);
        data = jsRoutes.controllers.FloatController.queryOptionalDefault(Infinity);
        assert.equal(path + "?x%3F%3D=Infinity", data.url);
        data = jsRoutes.controllers.FloatController.queryOptionalDefault(-Infinity);
        assert.equal(path + "?x%3F%3D=-Infinity", data.url);
    });
    it("should be correct for list query param", function () {
        let path = "/float-list";
        var data = jsRoutes.controllers.FloatController.queryList(null);
        assert.equal(path, data.url);
        data = jsRoutes.controllers.FloatController.queryList();
        assert.equal(path, data.url);
        data = jsRoutes.controllers.FloatController.queryList(undefined);
        assert.equal(path, data.url);
        data = jsRoutes.controllers.FloatController.queryList([]);
        assert.equal(path, data.url);
        data = jsRoutes.controllers.FloatController.queryList(testList);
        assert.equal(path + "?x%5B%5D=7.7&x%5B%5D=-8.8&x%5B%5D=9.9e-10", data.url);
        data = jsRoutes.controllers.FloatController.queryList(infinityList);
        assert.equal(path + "?x%5B%5D=NaN&x%5B%5D=Infinity&x%5B%5D=-Infinity", data.url);
    });
    it("should be correct for list default query param", function () {
        let path = "/float-list-d";
        var data = jsRoutes.controllers.FloatController.queryListDefault(null);
        assert.equal(path, data.url);
        data = jsRoutes.controllers.FloatController.queryListDefault();
        assert.equal(path, data.url);
        data = jsRoutes.controllers.FloatController.queryListDefault(undefined);
        assert.equal(path, data.url);
        data = jsRoutes.controllers.FloatController.queryListDefault([]);
        assert.equal(path, data.url);
        data = jsRoutes.controllers.FloatController.queryListDefault(defaultList);
        assert.equal(path + "?x%5B%5D%3D=1.1&x%5B%5D%3D=2.2&x%5B%5D%3D=3.3", data.url);
        data = jsRoutes.controllers.FloatController.queryListDefault(testList);
        assert.equal(path + "?x%5B%5D%3D=7.7&x%5B%5D%3D=-8.8&x%5B%5D%3D=9.9e-10", data.url);
        data = jsRoutes.controllers.FloatController.queryListDefault(infinityList);
        assert.equal(path + "?x%5B%5D%3D=NaN&x%5B%5D%3D=Infinity&x%5B%5D%3D=-Infinity", data.url);
    });
    it("should be correct for list nullable query param", function () {
        let path = "/float-list-null";
        var data = jsRoutes.controllers.FloatController.queryListNullable(null);
        assert.equal(path, data.url);
        data = jsRoutes.controllers.FloatController.queryListNullable();
        assert.equal(path, data.url);
        data = jsRoutes.controllers.FloatController.queryListNullable(undefined);
        assert.equal(path, data.url);
        data = jsRoutes.controllers.FloatController.queryListNullable([]);
        assert.equal(path, data.url);
        data = jsRoutes.controllers.FloatController.queryListNullable(testList);
        assert.equal(path + "?x%5B%5D%3F=7.7&x%5B%5D%3F=-8.8&x%5B%5D%3F=9.9e-10", data.url);
        data = jsRoutes.controllers.FloatController.queryListNullable(infinityList);
        assert.equal(path + "?x%5B%5D%3F=NaN&x%5B%5D%3F=Infinity&x%5B%5D%3F=-Infinity", data.url);
    });
    it("should be correct for list optional query param", function () {
        let path = "/float-list-opt";
        var data = jsRoutes.controllers.FloatController.queryListOptional(null);
        assert.equal(path, data.url);
        data = jsRoutes.controllers.FloatController.queryListOptional();
        assert.equal(path, data.url);
        data = jsRoutes.controllers.FloatController.queryListOptional(undefined);
        assert.equal(path, data.url);
        data = jsRoutes.controllers.FloatController.queryListOptional([]);
        assert.equal(path, data.url);
        data = jsRoutes.controllers.FloatController.queryListOptional(testList);
        assert.equal(path + "?x%5B%5D%3F=7.7&x%5B%5D%3F=-8.8&x%5B%5D%3F=9.9e-10", data.url);
        data = jsRoutes.controllers.FloatController.queryListOptional(infinityList);
        assert.equal(path + "?x%5B%5D%3F=NaN&x%5B%5D%3F=Infinity&x%5B%5D%3F=-Infinity", data.url);
    });
    it("should be correct for list optional default query param", function () {
        let path = "/float-list-opt-d";
        var data = jsRoutes.controllers.FloatController.queryListOptionalDefault(null);
        assert.equal(path, data.url);
        data = jsRoutes.controllers.FloatController.queryListOptionalDefault();
        assert.equal(path, data.url);
        data = jsRoutes.controllers.FloatController.queryListOptionalDefault(undefined);
        assert.equal(path, data.url);
        data = jsRoutes.controllers.FloatController.queryListOptionalDefault([]);
        assert.equal(path, data.url);
        data = jsRoutes.controllers.FloatController.queryListOptionalDefault(defaultList);
        assert.equal(path + "?x%5B%5D%3F%3D=1.1&x%5B%5D%3F%3D=2.2&x%5B%5D%3F%3D=3.3", data.url);
        data = jsRoutes.controllers.FloatController.queryListOptionalDefault(testList);
        assert.equal(path + "?x%5B%5D%3F%3D=7.7&x%5B%5D%3F%3D=-8.8&x%5B%5D%3F%3D=9.9e-10", data.url);
        data = jsRoutes.controllers.FloatController.queryListOptionalDefault(infinityList);
        assert.equal(path + "?x%5B%5D%3F%3D=NaN&x%5B%5D%3F%3D=Infinity&x%5B%5D%3F%3D=-Infinity", data.url);
    });
});
